<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"KB-3-2");
$colname_edit = "-1";
if (isset($_GET['noreferensi'])) {
  $colname_edit = (get_magic_quotes_gpc()) ? $_GET['noreferensi'] : addslashes($_GET['noreferensi']);
}
mysql_select_db($database_con_gl, $con_gl);
$query_edit = sprintf("SELECT * FROM gl_rtrans WHERE no_ref = '$_GET[noreferensi]'", $colname_edit);
$edit = mysql_query($query_edit, $con_gl) or die(mysql_error());
$row_edit = mysql_fetch_assoc($edit);
$totalRows_edit = mysql_num_rows($edit);

mysql_select_db($database_con_gl, $con_gl);
$query_klas = "SELECT kd, klasifikasi, keterangan, neraca, ruglab, tipe FROM gl_klas where `tipe` <>'6' and `tipe` <>'7' ORDER BY kd,klasifikasi ASC";
$klas = mysql_query($query_klas, $con_gl) or die(mysql_error());
$row_klas = mysql_fetch_assoc($klas);
$totalRows_klas = mysql_num_rows($klas);

mysql_select_db($database_con_gl, $con_gl);
$query_kontak = "SELECT id, nama, type FROM gl_kontak ORDER BY type, nama ASC";
$kontak = mysql_query($query_kontak, $con_gl) or die(mysql_error());
$row_kontak = mysql_fetch_assoc($kontak);
$totalRows_kontak = mysql_num_rows($kontak);

mysql_select_db($database_con_gl, $con_gl);
$query_klaskas = "SELECT kd, klasifikasi FROM gl_klas WHERE tipe = 2 ORDER BY kd,klasifikasi ASC";
$klaskas = mysql_query($query_klaskas, $con_gl) or die(mysql_error());
$row_klaskas = mysql_fetch_assoc($klaskas);
$totalRows_klaskas = mysql_num_rows($klaskas);

mysql_select_db($database_con_gl, $con_gl);
$query_def_ak = "SELECT gl_company.a_kas FROM gl_company";
$def_ak = mysql_query($query_def_ak, $con_gl) or die(mysql_error());
$row_def_ak = mysql_fetch_assoc($def_ak);
$totalRows_def_ak = mysql_num_rows($def_ak);

mysql_select_db($database_con_gl, $con_gl);
$query_get_id = "SELECT gl_trans.id, gl_trans.akun FROM gl_trans WHERE gl_trans.no_ref='$_GET[noreferensi]' AND gl_trans.pos='K'";
$get_id = mysql_query($query_get_id, $con_gl) or die(mysql_error());
$row_get_id = mysql_fetch_assoc($get_id);
$totalRows_get_id = mysql_num_rows($get_id);

mysql_select_db($database_con_gl, $con_gl);
$query_list_trans = "SELECT gl_trans.id, gl_trans.no_ref, gl_trans.transaksi, gl_trans.total, gl_akun.akun, gl_akun.id as akun_id FROM gl_trans, gl_akun WHERE gl_trans.pos='D' AND gl_akun.id = gl_trans.akun  AND gl_trans.no_ref='$_GET[noreferensi]' ORDER BY gl_trans.id";
$list_trans = mysql_query($query_list_trans, $con_gl) or die(mysql_error());
$row_list_trans = mysql_fetch_assoc($list_trans);
$totalRows_list_trans = mysql_num_rows($list_trans);
// ---
mysql_select_db($database_con_gl, $con_gl);
$query_gudang = "SELECT id, gudang FROM gl_gudang";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gudang .= " where id='$_SESSION[lokasi]'";
}
$query_gudang .=" ORDER BY gudang ASC";
$gudang = mysql_query($query_gudang, $con_gl) or die(mysql_error());
$row_gudang = mysql_fetch_assoc($gudang);
$totalRows_gudang = mysql_num_rows($gudang);

$totdeb = 0;
$totkre = 0;
?>
<link href="js/ui.datepicker.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/ajax_data.js"></script>
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript">
<!--
$(function()
      {
        $('.calendar').datepicker({
            appendText : "yyyy/mm/dd",
            dateFormat : 'yy/mm/dd'
          });
      });
</script>
<script type="text/javascript">
$(document).ready(function() {

	$().ajaxStart(function() {
		$('#loading').show();
		$('#result').hide();
	}).ajaxStop(function() {
		$('#loading').hide();
		$('#result').fadeIn('slow');
	});

	$('#edit').submit(function() {
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data) {
				$('#result').html(data);
			}
		})
		return false;
	});
  $('#result').click(function(){
  $(this).hide();
  });
})
</script>
<div id="loading" style="display:none;"><img src="images/loading.gif" alt="loading..." /></div>
<div id="result" style="display:none;"></div>
<h1> Edit Kas Keluar </h1>
<form action="proses/kaskeluar.php?act=edit" method="POST" name="edit" id="edit">
  <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
    <tr>
      <td width="15%" align="right" valign="top">Akun Kas *: </td>
      <td width="33%" valign="top"><label>
      <select name="akunkas" id="akunkas">
        <?php
do {  
mysql_select_db($database_con_gl, $con_gl);
$query_kasakun = "SELECT id, akun FROM gl_akun where klasifikasi='$row_klaskas[kd]' ORDER BY akun ASC";
$kasakun = mysql_query($query_kasakun, $con_gl) or die(mysql_error());
$row_kasakun = mysql_fetch_assoc($kasakun);
$totalRows_kasakun = mysql_num_rows($kasakun);
?>
        <option value="" style="background:#DDDDDD;font-weight:bold;"><?php echo $row_klaskas['klasifikasi']?></option>
        <?php if($totalRows_kasakun > 0) { ?>
        <?php do { ?>
        <option value="<?php echo $row_kasakun['id']; ?>" <?php if($row_kasakun['id']==$row_get_id['akun']) { ?>Selected="selected"<?php } ?>>-<?php echo $row_kasakun['akun']; ?></option>
        <?php } while ($row_kasakun = mysql_fetch_assoc($kasakun)); ?>
        <?php } ?>
        <?php
} while ($row_klaskas = mysql_fetch_assoc($klaskas));
  $rows = mysql_num_rows($klaskas);
  if($rows > 0) {
      mysql_data_seek($klaskas, 0);
	  $row_klaskas = mysql_fetch_assoc($klaskas);
  }
?>
      </select>
      <input name="trans_id" type="hidden" id="trans_id" value="<?php echo $row_get_id['id']; ?>" />
      </label></td>
      <td width="12%" align="right" valign="top">Dari *: </td>
      <td width="44%" valign="top"><label>
      <select name="dari" id="dari" onchange="setKeterangan(this.value);">
        <option value="" <?php if (!(strcmp("", $row_edit['kontak']))) {echo "selected=\"selected\"";} ?>>Pilih Kontak</option>
        <?php
do {  
?>
        <option value="<?php echo $row_kontak['id']?>"<?php if (!(strcmp($row_kontak['id'], $row_edit['kontak']))) {echo "selected=\"selected\"";} ?>><?php echo $row_kontak['nama']?></option>
        <?php
} while ($row_kontak = mysql_fetch_assoc($kontak));
  $rows = mysql_num_rows($kontak);
  if($rows > 0) {
      mysql_data_seek($kontak, 0);
	  $row_kontak = mysql_fetch_assoc($kontak);
  }
?>
      </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top">No. Referensi *:</td>
      <td valign="top"><div id="refDiv">
        <label>
          <input name="noreferensi" type="text" id="noreferensi" value="<?php echo $row_edit['no_ref']; ?>" size="20" maxlength="20" onchange="cekReferensi(this.value);" onfocus="this.blur();"/>
          </label>
      </div></td>
      <td align="right" valign="top">Lokasi Kantor *:</td>
      <td valign="top"><label>
        <select name="gudang" id="gudang">
          <?php
do {  
?>
          <option value="<?php echo $row_gudang['id']?>" <?php if($row_gudang['id']==$row_edit['gudang']) { ?>selected="selected"<?php } ?>><?php echo $row_gudang['gudang']?></option>
          <?php
} while ($row_gudang = mysql_fetch_assoc($gudang));
  $rows = mysql_num_rows($gudang);
  if($rows > 0) {
      mysql_data_seek($gudang, 0);
	  $row_gudang = mysql_fetch_assoc($gudang);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top">      Tanggal *: </td>
      <td valign="top"><label><input name="tanggal" type="text" class="calendar" id="tanggal" value="<?php echo $row_edit['tgl']; ?>" size="20" maxlength="15"/>
      </label>      </td>
      <td align="right" valign="top">Keterangan :</td>
      <td valign="top"><div id="divKeterangan"><label>
      <textarea name="keterangan" cols="40" rows="2" id="keterangan"><?php echo $row_edit['keterangan']; ?></textarea>
      </label></div></td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td colspan="3"><div id="ajaxDiv">
	      <table width="100%" border="0" cellspacing="0" cellpadding="5" class="datatable">
            <tr>
              <th width="10%" align="center"><strong>Kode</strong></th>
              <th width="36%" align="center"><strong>Akun</strong></th>
              <th width="10%" align="center"><strong>Nilai (D) </strong></th>
              <th align="center"><strong>Transaksi</strong></th>
              <th width="10%" align="center"><strong>Aksi</strong></th>
            </tr>
            <?php $tot_x = 0;do { ?>		  
	          <tr valign="top" bgcolor="#FFFFFF">
		        <td width="10%" align="center"><?php echo $row_list_trans['akun_id']; ?></td>
		        <td width="36%" align="center"><?php echo $row_list_trans['akun']; ?></td>
		        <td width="10%" align="right"><?php echo number_format($row_list_trans['total'],0,',','.').",-"; $tot_x += $row_list_trans['total'];?></td>
			    <td align="center"><?php echo $row_list_trans['transaksi']; ?></td>
			    <td width="10%" align="center"> <label>
        <button value="<?php echo $row_list_trans['id']; ?>" onclick="ajaxEditFormKaskeluar(<?php echo $row_list_trans['id']; ?>);" type="button" class="editbutton" title="Edit Transaksi">&nbsp;</button></label><label>
        <input name="hapus" type="button" id="hapus" value="&nbsp;" onclick="ajaxManageKaskeluar('Hapus',<?php echo $row_list_trans['id']; ?>);" title="Hapus Transaksi" class="deletebutton"/>
</label></td>
		      </tr>
			  <?php } while ($row_list_trans = mysql_fetch_assoc($list_trans)); ?>
			  <tr bgcolor="#FFFFFF">
		          <td width="10%" align="center">&nbsp;</td>
		          <td width="36%" align="right"><strong>Total : </strong></td>
		          <td width="10%" align="right"><?php echo number_format($tot_x,0,',','.').",-";?>
                <input name="total" type="hidden" id="total" value="<?php echo $tot_x;?>" size="10" maxlength="15" /></td>
		          <td align="center">&nbsp;</td>
		          <td width="10%" align="center">&nbsp;</td>
	          </tr>
            <tr>
              <th width="10%" align="center"><strong>Kode</strong></th>
              <th width="36%" align="center"><strong>Akun</strong></th>
              <th width="10%" align="center"><strong>Nilai (D) </strong></th>
              <th align="center"><strong>Transaksi</strong></th>
              <th width="10%" align="center"><strong>Aksi</strong></th>
            </tr>
            <tr valign="top" bgcolor="#FFFFFF">
              <td width="10%" align="center"><div id="kodeDiv">
                <label>
                <input name="akunkd" type="text" id="akunkd" size="10" maxlength="10" onchange="cekAkun(this.value);"/>
                </label>
              </div></td>
			
              <td width="36%" align="center">
			  <div id="akunDiv">
			    <label>
              <select name="akun" id="akun" onchange="cekKode(this.value);">
                <?php do {  ?>
<?php
mysql_select_db($database_con_gl, $con_gl);
$query_akun = "SELECT id, akun, klasifikasi, keterangan FROM gl_akun where klasifikasi = '$row_klas[kd]' ORDER BY id,akun ASC";
$akun = mysql_query($query_akun, $con_gl) or die(mysql_error());
$row_akun = mysql_fetch_assoc($akun);
$totalRows_akun = mysql_num_rows($akun);
?>
               
                <option value="" style="background:#EEEEEE; font-weight:bold;"><?php echo $row_klas['kd']." - ";echo $row_klas['klasifikasi'];?></option>
				<?php do { ?>
				<option value="<?php echo $row_akun['id']?>">-<?php echo $row_akun['akun']?></option>
				<?php } while ($row_akun = mysql_fetch_assoc($akun));?>
                <?php
} while ($row_klas = mysql_fetch_assoc($klas));
  $rows = mysql_num_rows($klas);
  if($rows > 0) {
      mysql_data_seek($klas, 0);
	  $row_klas = mysql_fetch_assoc($klas);
  }
?>
              </select>
              </label></div></td>
              <td width="10%" align="center"><label>
                <input name="nilai" type="text" id="nilai" size="10"/>
              </label></td>
              <td align="center"><label>
              <textarea name="transaksi" cols="45" rows="3" id="transaksi"></textarea>
              </label></td>
              <td width="10%" align="center">
                  <label>
                  <input name="add" type="button" id="add" value="&nbsp;" onclick="ajaxManageKaskeluar('Tambah');" class="checkbutton" title="Tambah Transaksi"/>
              </label></td>
            </tr>
          </table>
      </div></td>
    </tr>
    <tr>
      <td align="left"><em>*Harus diisi</em></td>
      <td colspan="3" align="right"><input name="jenis" type="hidden" id="jenis" value="4" />
        <label>
        <input name="Simpan" type="submit" id="Simpan" value="Simpan Jurnal" />
      </label></td>
    </tr>
  </table>
</form>
